package sg.edu.nus.iss.vmcs.ui;

import java.awt.Frame;
import java.awt.GridLayout;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JDialog;

import sg.edu.nus.iss.vmcs.controller.BrandStoreController;
import sg.edu.nus.iss.vmcs.controller.CashStoreController;
import sg.edu.nus.iss.vmcs.controller.MainController;
import sg.edu.nus.iss.vmcs.controller.StoreController1;
import sg.edu.nus.iss.vmcs.controller.TransactionController;
import sg.edu.nus.iss.vmcs.entity.BrandDrink;
import sg.edu.nus.iss.vmcs.entity.Coin;
import sg.edu.nus.iss.vmcs.entity.DrinksBrand;
import sg.edu.nus.iss.vmcs.entity.StoreItem;
import sg.edu.nus.iss.vmcs.util.Environment;
import sg.edu.nus.iss.vmcs.util.VMCSException;

public class CustomerPanel extends JDialog {
	
	private static Map<String, Coin> coins = new HashMap<String, Coin>();
	private static Map<String, BrandDrink> brands = new HashMap<String, BrandDrink>();
	//MainController mainController  = MainController.getInstance();
	

	public static Map<String, Coin> getCoins() {
		return coins;
	}

	public static Map<String, BrandDrink> getBrands() {
		return brands;
	}

	public CustomerPanel(Frame fr, Object customerController) {
		//super(fr, "Customer Panel", false);
		
		init();
	}
	
	private void init() {
		/*
		 * Cuong: init the StoreController
		 */
		//MainController.initInstance("source/vmcs.properties");
		//StoreController1 drinkStoreController = mainController.getStoreController("DRINK");
		//StoreController1 cashStoreController = mainController.getStoreController("CASH");
		BrandStoreController  drinkStoreController= BrandStoreController.getInstance();
		CashStoreController   cashStoreController = CashStoreController.getInstance();
		
		StoreItem[] drinkItems = drinkStoreController.getItems();
		StoreItem[] cashItems = cashStoreController.getItems();
		
		for(int i =0 ;i<drinkItems.length;i++)
		{
			System.out.print("Class "+drinkItems[i].getContent());
			BrandDrink drink = (BrandDrink) drinkItems[i].getContent();		
			brands.put(drink.getId(),drink);
		}
		
		for(int i =0 ;i<cashItems.length;i++)
		{
			Coin coin = (Coin) cashItems[i].getContent();		
			double value = coin.getValue();
			coins.put(coin.getId(), coin);
		}
		//coins.put("-1", new Coin("-1", 0, 0, 0, 0, null, null));
		
		/*
		coins.put("5", new Coin("5", 5.0, 100, 5, 1.5, "himg1", "timg1"));
		coins.put("10", new Coin("10", 10.0, 150, 5, 2, "himg2", "timg2"));
		coins.put("20", new Coin("20", 20.0, 20, 5, 2.5, "himg3", "timg3"));
		coins.put("50", new Coin("50", 50.0, 500, 5, 2.5, "himg4", "timg4"));
		coins.put("100", new Coin("100", 100.0, 2000, 5, 3, "himg5", "timg5"));
		coins.put("-1", new Coin("-1", 0, 0, 0, 0, null, null));

		brands.put("1",new DrinksBrand("1","Coca Cola", 120f));
		brands.put("2",new DrinksBrand("2","Sarsi", 120f));
		brands.put("3",new DrinksBrand("3","Pepsi", 120f));
		brands.put("4",new DrinksBrand("4","Soya bean", 120f));
		brands.put("5",new DrinksBrand("5","Fanta", 120f));
		*/
				
		
		setLayout(new GridLayout(2, 1));
		
		TransactionController txnController = new TransactionController();
		
		CoinInputBox cbox = new CoinInputBox(txnController);
		DrinkSelectionBox dbox = new DrinkSelectionBox(cbox, txnController);
		
		add(cbox.getCoinInputBoxPanel());
		add(dbox.getDrinkSelectedBoxPanel());
		
		setVisible(true);
		setDefaultCloseOperation(DISPOSE_ON_CLOSE);
		setSize(400, 400);
		pack();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			Environment.initialize("source\\vmcs.properties");
		} catch (VMCSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		CustomerPanel cp = new CustomerPanel(null, null);
	}

}
